package worker.control;

import java.util.Date;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import worker.model.service.SpcService;
import worker.model.vo.MemberVO;

public class SpcController extends MultiActionController {
	private SpcService spcService;
	
	public void setSpcService(SpcService spcService) {
		this.spcService = spcService;
	}
	/**
	 * 120526 조철희
	 * SPC 메뉴 첫 화면
	 */
	public ModelAndView fmb(HttpServletRequest request, HttpServletResponse response){
		System.out.println("fmb  join..");
		HashMap map = spcService.getFmbInfoStatics();
		System.out.println(map);
		return new ModelAndView("fmb.fmb_main","map",map);
	}
	/**
	 * 120526 조철희
	 * SPC 메뉴 첫 화면
	 */
	public ModelAndView main(HttpServletRequest request, HttpServletResponse response){
		System.out.println("main  join..");
		HashMap map = spcService.getSpcInfoStatics();
		System.out.println(map);
		return new ModelAndView("spc.spc_main","map",map);
	}
	/**
	 * 120529 조철희
	 * SPC 메뉴 자동 새로고침 (2000 millis  마다)
	 */
	public ModelAndView recycleMain(HttpServletRequest request, HttpServletResponse response) throws InterruptedException{
		System.out.println("recycleMain  join..");
		Thread.sleep(500);
		HashMap map = spcService.getFmbInfoStatics();
		return new ModelAndView("JsonView","map",map);
	}
	/**
	 * 120526 조철희
	 * 로그인
	 */
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response, MemberVO mvo){
		System.out.println("login join..mvo : "+mvo);
		String msg="Y";
		Object obj= spcService.login(mvo);
		if(obj!=null){
			mvo = (MemberVO) obj;
			request.getSession().setAttribute("vo",mvo);
		}else{
			System.out.println(" obj ==null else : "+obj);
			msg="N";
		}
		return new ModelAndView("JsonView","msg",msg);
	}
	/**
	 * 120527 조철희
	 * 로그아웃
	 */
	public ModelAndView logout(HttpServletRequest request, HttpServletResponse response){
		request.getSession().invalidate();
		return new ModelAndView("index");
	}
	/**
	 * 120601 조철희
	 * 전날 생산량, 불량품량 DB 저장 (Statics)
	 */
	public ModelAndView statics(HttpServletRequest request, HttpServletResponse response){
		System.out.println("statics join..");
		HashMap map = new HashMap();
		map.put("ok_amount",request.getParameter("ok_amount"));
		map.put("fail_amount",request.getParameter("fail_amount"));
		String flag = spcService.statics(map);
		return new ModelAndView("JsonView","flag",flag);
	}
}
